package com.es.controller;

import com.es.service.ParseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class ParseController {

    private final ParseService parseService;

    @Autowired
    public ParseController(ParseService parseService) {
        this.parseService = parseService;
    }

    @GetMapping("/parse/{keyword}")
    public Boolean parseSource(@PathVariable("keyword") String keyword) throws Exception {
        return parseService.parseSource(keyword);
    }

    @GetMapping("/search/{keyword}/{pageNum}/{pageSize}")
    public List<Map<String, Object>> searchPage(@PathVariable("keyword") String keyword,
                                                @PathVariable("pageNum") Integer pageNum,
                                                @PathVariable("pageSize") Integer pageSize) throws IOException {
        return parseService.highlightPage(keyword,pageNum,pageSize);
    }
}
